InfoConnect VBA Guide
Quickstart / Create a Macro with the VBA Editor
In This Topic
    Create a Macro with the VBA Editor
    In This Topic

    This example shows how to create a macro that gets text from the screen and displays it in a message box.

    This article contains tabbed content that is specific to each terminal type. Be sure the tab for your Which Terminal Type are you Using? is selected.

    Create a macro       

    1. On the Tools tab, select Visual Basic to open the Visual Basic Editor.
    2. In the Visual Basic Project Explorer, right click on the project folder, and choose Insert > Module.  
    3. In the code window, add a subroutine by entering Sub followed by the name for the macro. For this example, enter Sub CopyTextMacro(). The editor creates the End Sub line.
      The name you choose for the subroutine must follow the Visual Basic naming conventions for macros. For more information, see Naming Macros.
    4. Enter the code for the macro in your new subroutine as shown below and then save your new macro.           
      Get text from the screen
      Copy Code
      Sub CopyTextMacro()
          'Create a variable to hold the text
          Dim screenText As String
            
          'Get text from the screen starting at screen row 1, column 1, and 30 characters long
           screenText = ThisIbmScreen.GetText(1, 1, 30)
            
          'Display the text in a message box
          MsgBox (screenText )
      End Sub
      
      Get text from the screen
      Copy Code
      Sub CopyTextMacro()
          'Create a variable to hold the text
          Dim screenText As String
             
          'Get text from the screen starting at screeen column 1, row 1
          ' and ending at row 30, column 30
           screenText = ThisScreen.GetText2(1, 1, 30, 30)
             
          'Display the text in a message box
          MsgBox (screenText )
      End Sub
      
    5. Place the cursor anywhere in the procedure (Sub) you just created and then press F5.
      The message box should display the text on the first line. (If your screen doesn't have any text in the upper left part of the display area, you may need to change the row and column arguments and run the macro again to display some text.)

    Concepts

    This macro uses an InfoConnect property (ThisScreen for Open Systems or ThisIbmScreen for IBM) to get the screen object for the session. You can use this property to get the screen object for any macro in a session project. InfoConnect provides several other properties that you can use to get key objects when you are creating macros in session projects. For more about these properties, see Using the InfoConnect Object Model.

    The screen object represents the host application screen and it provides methods and properties used to access host screen data. The GetText method used in the IBM sample is used to get the text from a screen location. The Open Systems library also has a GetText method that you can use in the same way.

    The GetText2 method used in the Open Systems sample is used to get the text in a region of the screen. The IBM library GetTextEx method can be used for the same purpose.  

     

    See Also